import http from "@/utils/http";
import { Upload } from "@/api/interface";

export const uploadFile = (params: FormData) => {
	return http.upload<Upload.ResFileList>((import.meta.env.VITE_API_URL as string) + `/file/uploadFile`, params, {
		headers: { "Content-Type": "multipart/form-data" }
	});
};
export const downloadFile = (fileName: string, id: string) => {
  http
    .download(
      (import.meta.env.VITE_API_URL as string) + `/file/downloadFileByFileId`,
      { fileName, fileId: id }
    )
    .then((res) => {
      ElMessage.success({ message: "下载成功！" });
      const blob = new Blob([res]); //处理文档流
      const link = document.createElement("a");
      link.download = fileName;
      link.style.display = "none";
      link.href = URL.createObjectURL(blob);
      document.body.appendChild(link);
      link.click();
      URL.revokeObjectURL(link.href); // 释放URL 对象
      document.body.removeChild(link);
    });
};
